import datetime


class OperatorMixins:
    def perform_create(self, serializer):
        user_name = getattr(self.request.user, "username", None)

        serializer.save(
            operator_name=user_name,
        )

    def perform_update(self, serializer):
        user_name = getattr(self.request.user, "username", None)
        print('user_name', user_name)
        serializer.save(operator_name=user_name)

    def perform_destroy(self, instance):
        instance.delete_time = datetime.datetime.now()
        user_name = getattr(self.request.user, "username", None)
        instance.operator_name=user_name
        instance.save()